package cn.xiaopengstack.trigger.http;

import cn.xiaopengstack.domain.strategy.model.entity.StrategyAwardEntity;
import cn.xiaopengstack.domain.strategy.service.raffle.IRaffleAward;
import cn.xiaopengstack.domain.strategy.service.raffle.IRaffleStrategy;
import cn.xiaopengstack.trigger.api.IRaffleStrategyService;
import cn.xiaopengstack.trigger.api.dto.RaffleAwardListRequestDTO;
import cn.xiaopengstack.trigger.api.dto.RaffleAwardListResponseDTO;
import cn.xiaopengstack.types.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author jiangyangang
 */
@Slf4j
@RestController
@RequestMapping("/api/${app.config.api-version}/raffle/strategy")
@Deprecated
//@CrossOrigin("${app.config.cross-origin}")
public class RaffleStrategyController implements IRaffleStrategyService {

    @Resource
    private IRaffleAward raffleAward;

    @Resource
    private IRaffleStrategy raffleStrategy;

    /**
     * 查询奖品列表
     * <a href="http://localhost:8091/api/v1/raffle/query_raffle_award_list">/api/v1/raffle/query_raffle_award_list</a>
     * 请求参数 raw json
     *
     * @param requestDTO {"strategyId":1000001}
     * @return 奖品列表
     */
    @RequestMapping(value = "query_raffle_award_list", method = RequestMethod.POST)
    public Response<List<RaffleAwardListResponseDTO>> queryRaffleAwardList(@RequestBody RaffleAwardListRequestDTO requestDTO) {
        List<StrategyAwardEntity> awardEntities = raffleAward.queryRaffleStrategyAwardList(requestDTO.getStrategyId());

        return Response.success(awardEntities.stream()
                .map((award) -> RaffleAwardListResponseDTO.builder()
                        .awardId(award.getAwardId())
                        .awardSubtitle(award.getAwardSubtitle())
                        .awardTitle(award.getAwardTitle())
                        .sort(award.getSort()).build())
                .collect(Collectors.toList()));
    }

}
